/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    color: white;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Main game container with responsive height */
#gameContainer {
    width: 100%;
    height: 450px; /* Default iframe height */
    position: relative;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #87CEEB 0%, #4682B4 50%, #2F4F4F 100%);
    overflow: hidden;
}

/* Responsive height for full browser */
@media (min-height: 500px) {
    #gameContainer {
        height: 90vh;
    }
}

/* Game header with essential information */
#gameHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
    height: 40px;
}

#gameHeader > div {
    color: #FFD700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Buttons styling */
button {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    min-height: 32px;
    white-space: nowrap;
}

button:hover {
    background: linear-gradient(145deg, #5CBF60, #4CAF50);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

#pauseBtn, #modeToggle {
    background: linear-gradient(145deg, #FF6B6B, #FF5252);
    font-size: 16px;
    min-width: 40px;
}

#modeToggle {
    background: linear-gradient(145deg, #9C27B0, #8E24AA);
    font-size: 10px;
    padding: 6px 8px;
}

/* Prompt panel */
#promptPanel {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    text-align: center;
    padding: 12px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 8px;
    margin: 8px 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    border: 3px solid #FFD700;
}

/* Main game area */
#gameArea {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(135, 206, 235, 0.3) 0%, rgba(70, 130, 180, 0.3) 100%);
}

/* Detective character */
#detective {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 40px;
    z-index: 10;
    transition: left 0.2s ease;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
    cursor: pointer;
}

/* Falling cards */
.card {
    position: absolute;
    background: white;
    color: #333;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid #4CAF50;
    min-width: 80px;
    max-width: 120px;
    word-wrap: break-word;
    z-index: 5;
    transition: all 0.1s ease;
}

.card.correct {
    border-color: #4CAF50;
    background: linear-gradient(145deg, #E8F5E8, #C8E6C9);
}

.card.incorrect {
    border-color: #F44336;
    background: linear-gradient(145deg, #FFEBEE, #FFCDD2);
}

/* Touch controls */
#touchControls {
    display: flex;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    height: 56px;
}

#leftBtn, #rightBtn {
    font-size: 24px;
    width: 60px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(145deg, #2196F3, #1976D2);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Progress bar */
#progressContainer {
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    margin: 0 12px 8px 12px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

#progressBar {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Game over and pause screens */
#gameOverScreen, #pauseScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    text-align: center;
    padding: 20px;
}

#gameOverScreen h2, #pauseScreen h2 {
    font-size: 28px;
    margin-bottom: 20px;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#gameOverScreen p {
    font-size: 18px;
    margin-bottom: 10px;
}

#leaderboard {
    margin-top: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 8px;
    max-width: 300px;
}

#leaderboard h3 {
    color: #FFD700;
    margin-bottom: 10px;
}

#scoresList {
    text-align: left;
    color: white;
}

#scoresList li {
    margin-bottom: 5px;
    font-size: 14px;
}

/* Level up animation */
#levelUpAnimation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    text-align: center;
    pointer-events: none;
}

.level-up-text {
    font-size: 36px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    animation: levelUpPulse 2s ease-in-out;
}

.level-up-number {
    font-size: 48px;
    font-weight: bold;
    color: #4CAF50;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    animation: levelUpScale 2s ease-in-out;
}

/* Animations */
@keyframes levelUpPulse {
    0%, 100% { transform: scale(1); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
}

@keyframes levelUpScale {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

@keyframes cardFall {
    from { transform: translateY(-100px); }
    to { transform: translateY(400px); }
}

/* Dynamic fall distance tied to container height so cards reach the detective */
@keyframes cardFallDynamic {
    from { transform: translateY(-100px); }
    to { transform: translateY(var(--fall-distance, 700px)); }
}

@keyframes scorePopup {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* Visual effects */
.score-popup {
    position: absolute;
    font-size: 24px;
    font-weight: bold;
    color: #4CAF50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: scorePopup 1s ease-out forwards;
    z-index: 50;
    pointer-events: none;
}

.score-popup.negative {
    color: #F44336;
}

/* Tooltip */
#tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 1000;
    pointer-events: none;
    max-width: 200px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Hidden class */
.hidden {
    display: none !important;
}

/* Mobile optimizations */
@media (max-width: 600px) {
    #gameHeader {
        font-size: 12px;
        padding: 6px 8px;
        height: 36px;
    }
    
    #promptPanel {
        font-size: 16px;
        padding: 10px;
        margin: 6px 8px;
    }
    
    #detective {
        font-size: 36px;
        bottom: 15px;
    }
    
    .card {
        font-size: 14px;
        padding: 10px;
        min-width: 70px;
        max-width: 100px;
    }
    
    #touchControls {
        padding: 8px 16px;
        height: 48px;
    }
    
    #leftBtn, #rightBtn {
        width: 50px;
        height: 32px;
        font-size: 20px;
    }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
    .card {
        border-width: 3px;
    }
    
    button {
        border: 2px solid white;
    }
    
    #promptPanel {
        border-width: 4px;
    }
}
